﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LayerEntity.Sistema;
using System.Collections;

namespace System2012.Sistema.Documentos
{
    public partial class frmCorrelativos : DevExpress.XtraEditors.XtraForm
    {
        string idTranzac;
        string  idComp;
        string serie;
        public frmCorrelativos(ArrayList data)
        {
            InitializeComponent();
            idTranzac = data[0].ToString();
            idComp = data[1].ToString();
            serie = data[2].ToString();
            if (!BGWTipDoc.IsBusy) BGWTipDoc.RunWorkerAsync();
        }

        private void BGWTipDoc_DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result = System2012.SystemUtils.RecordManagerCommonList.GetDocument(2);
        }

        private void BGWTipDoc_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            cmbDocumento.Properties.DataSource = e.Result;
            if (!BGWTranzaccion.IsBusy) BGWTranzaccion.RunWorkerAsync();
        }

        private void BGWTranzaccion_DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result = System2012.SystemUtils.RecordManagerCommonList.GetTranzaccion();
        }

        private void BGWTranzaccion_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            CmbTranzaccion.Properties.DataSource = e.Result;
            if (!BGWSeries.IsBusy) BGWSeries.RunWorkerAsync();
        }

        private void BGWSeries_DoWork(object sender, DoWorkEventArgs e)
        {
            ESistema obj = new ESistema();
            StringBuilder cadena = new StringBuilder();
            cadena.Append("where id_tranzaccion='");
            cadena.Append(idTranzac+"' and ");
            cadena.Append(" serie='");
            cadena.Append(serie+"' and");
            cadena.Append(" id_documento=");
            cadena.Append(idComp + "");
            obj.Condicion = cadena.ToString();
            e.Result = System2012.SystemUtils.RecordManagerCommonList.GetListaSeriesDocumento(obj);
           
        }

        private void BGWSeries_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            DataTable dtb = (DataTable)e.Result;
            if (dtb.Rows.Count > 0)
            {
                cmbDocumento.EditValue =int.Parse( dtb.Rows[0]["id_documento"].ToString());
                CmbTranzaccion.EditValue = dtb.Rows[0]["id_tranzaccion"].ToString();
                txtSerie.Text = dtb.Rows[0]["serie"].ToString();
                txtCorrelativo.Text = dtb.Rows[0]["correlativo"].ToString();
                txtdesde.Text = dtb.Rows[0]["desde"].ToString();
                txtHasta.Text = dtb.Rows[0]["hasta"].ToString();
            }
        }
    }
}